Page({

  /**
   * 页面的初始数据
   */
  data: {
    taskId:'',
    details:[],
    picUrl:'',
    openid:''
  },
    /** 
   * 获取用户openid
  */
  getOpenid() {
    let that = this;
    wx.cloud.callFunction({
      name: 'getOpenid',
      complete: res => {
        console.log('云函数获取到的openid: ', res.result.openId)
        var openid = res.result.openId;
        that.setData({
          openid: openid
        })
      }
    })
  },
  /**
   * 访问接口
   */
  search:function(){
    wx.request({
      url: 'https://www.lanotherl.com/family/taskDetails',
      data:{
        taskId:this.data.taskId
      },
      success:res=>{
        console.log("访问接口成功，返回的数据为：",res)
        this.setData({
          details:res.data.data.details,
          picUrl:res.data.data.imgList[0].picUrl
        })

      },
      fail:err=>{
        console.log("数据请求错误",err)
      }
    })
  },
   /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      taskId: options.taskId
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var lostmanId_get = wx.getStorageSync('lostmanId');//wx.getStorageSync(key)，获取本地缓存
    if(this.data.taskId == -1){
      var taskId_get = wx.getStorageSync('taskId');//wx.getStorageSync(key)，获取本地缓存
      this.setData({
        taskId:taskId_get
      })
    }
    console.log("当前老人的lostmanId为：",lostmanId_get)
    console.log("当前老人的taskId为:",this.data.taskId)
    this.search();
    this.getOpenid();
  },
  /**
   * 确认接收该任务
   */
  submitBtn:function(){
    wx.request({
      url: 'https://www.lanotherl.com/volunteer/join',
      data:{
        taskId:this.data.taskId,
        openid:this.data.openid
      },
      method:"POST",
      // Post请求
      header: {
        "content-type": "application/x-www-form-urlencoded"
      },
      success:res=>{
        console.log("访问接口成功，返回的数据为：",res)
      },
      fail:err=>{
        console.log("数据请求错误",err)
      }
    })
  }
})